<?php 
session_start();

$user = $_SESSION['username'];
if (!$user) { header('location: login.php'); exit; }

include "../../includes/functions.php";

echo db_connect();

$days_of_week = array ("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
$start_hour = "6";
$finish_hour = "27";
$left_pos = 50;
$column_width = 100;


// build drop-down of shows
$query="SELECT * FROM shows ORDER BY name";
$result= mysql_query($query);

 while ($row= mysql_fetch_array($result)) {
 		$show_id=$row['show_id'];
		$show_name=$row['name'];
		// put selected if it's today, now logic here
		$select .= "<option value='$show_id'>$show_name</option>";
 }

 ?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>CJLY ADMINISTRATION</title>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" media="screen" href="../../includes/themes/coffee/grid.css" /> 
<link rel="stylesheet" type="text/css" media="screen" href="../../includes/themes/jqModal.css" /> 

<script type="text/javascript" src="../../calendar_picker_submit.js"></script>
<script type="text/javascript" src="../../includes/jquery.js"></script>

<link rel="stylesheet" type="text/css" media="screen" href="themes/ui.datepicker.css" />

<script type="text/javascript">


</script>

</head>

<body bgcolor="#eeeeee">
<a href="index.php"><< ADMINISTRATION Home</a>  
<table width="850" height="60" border="0" cellpadding="0" cellspacing="0">
<form action = "show_edit.php" method = "POST">  
<tr>
    <td colspan="3" class="index_table_hed" width="400"><div align="center">SHOWS Manager</div></td><td  class="index_table_hed"> <div class="edit_controls">  <select name="show_id" id="select">
    <option value="0">-- choose a show --</option>
    <?=$select?>
    </select> &nbsp; &nbsp;<input name="submit" type="submit" value="Edit it">
<br>
<a href="show_edit.php" style="font_size:9; color:white;">>Add a New Show</a>
		</div>
		 </td>
		
  </tr> </form>

</table>
<p>







<?php
echo "<div class='calendar_container_edit' style='background-image:url('../../images/calendar_bg.jpg'); background-color:cdcdcd;' >\n\n";  
echo "<div class='cal_header' style='padding-left:20px;'>";
$l = $left_pos;
foreach ($days_of_week as $dow) {
	$lpos = $l."px;";
  echo "<div class='calendar_days_head' style='left:$lpos width:".$column_width."px;'>$dow</div>"; 
  $l=$l + $column_width + 15; 
}
echo "</div>";
//echo "<div class=''>" ;  
   
echo "<div class='hours_scale_container'>\n";
$a = $start_hour;  
while ($a < $finish_hour) {
	if ($a >= 12) {$az=$a-12; $ampm="pm";} else {$az=$a; $ampm="am";}
	if ($a >= 24) {$az=$a-24; $ampm="am";}
	if ($az==0) $az=12;

 echo "<div class='hours_scale_item'>$az$ampm</div>\n";  
 $a++;  
}
echo "</div>\n\n";

  
foreach ($days_of_week as $day)  {
echo "<div class='day_column'>\n"; 
$query = "SELECT * FROM show_occurrances WHERE day_of_week = '$day' ORDER BY start_time";  
 $result = mysql_query($query); 

	while ($row = mysql_fetch_array ($result))  {
		$show_id = $row['show_id'];
		$occurrence_id = $row['id'];
		$sh_query = "SELECT * FROM shows where show_id = '$show_id'";
		$sh_result = mysql_query ($sh_query );
		$sh_row = mysql_fetch_array($sh_result );
		$show_name = $sh_row['name'];
		
		if (strLen($show_name) > 14) {$size = " font-size:10px;";} else {$size = "";} 
		  
		$start = $row['start_time'];
	  $end = $row['end_time'];
	  $top = (substr ($start, 0, 2) - $start_hour) * 50; if (substr ($start, 3, 2) == "30") $top = $top + 25;
	  $bottom = (substr ($end, 0, 2) - $start_hour ) * 50; if (substr ($end, 3, 2) == "30") $bottom = $bottom + 25; 
	 //echo "($bottom - $top)";  
  $height = ($bottom - $top) - 10; 
$top = $top."px;";
$height = $height."px;"; 
		echo "<div class='calendar_show' style='top:$top left:".$left_pos."px; height:$height max-height:$height width:".$column_width."px; $size' onClick='window.location = \"show_edit.php?soid=$occurrence_id\"'>$show_name</div>\n";
		
		
	}// end of day's shows
	
echo "</div>\n";
$left_pos = $left_pos + $column_width + 15;
} ///  end of day of week


?>



</body>
</html>
